package com.epro.dx.adapter;


import java.util.ArrayList;
import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import com.epro.dx.activity.coupon.fragment.LandingPageCategoryFragment;
import com.epro.dx.activity.coupon.fragment.LandingPageCategoryFragment.OnFlingStateChangedListener;
import com.weipu.common.facade.model.CatelogModel;
import com.weipu.common.facade.model.ProductModel;

public class PandingPageFragmentAdapter extends /*FragmentPagerAdapter*/FragmentStatePagerAdapter {
	private List<CatelogModel> cateModels;
	
	private ArrayList<ProductModel> productList;
	
	private String couponCode;
	
//	List<LandingPageCategoryFragment> fragmentList;
	
	LandingPageCategoryFragment currentFragment;

	private OnFlingStateChangedListener onFlingStateChangedListener;

	private String currencyCode;

	private String currencyCodeStr;
	
	public PandingPageFragmentAdapter(FragmentManager fm,List<CatelogModel> cateModels,ArrayList<ProductModel> productList,
			String couponCode,OnFlingStateChangedListener onFlingStateChangedListener,
			String currencyCode,String currencyCodeStr) {
		super(fm);
		this.cateModels=cateModels;
		this.productList=productList;  
		this.couponCode=couponCode;
		this.onFlingStateChangedListener = onFlingStateChangedListener;
		this.currencyCode = currencyCode;
		this.currencyCodeStr = currencyCodeStr;
	}
	
//	public PandingPageFragmentAdapter(FragmentManager fm,List<LandingPageCategoryFragment> fragments,List<CatelogModel> cateModels) {
//		super(fm);
//		this.fragmentList=fragments;
//		this.cateModels=cateModels;
//	}

	@Override
	public CharSequence getPageTitle(int position) {
		return cateModels.get(position).getShortName();
	}

	@Override
	public int getCount() {
		return cateModels.size();
//		return fragmentList.size();
	}

	@Override
	public Fragment getItem(int position) {
//		return fragmentList.get(position);
		return LandingPageCategoryFragment.newInstance(position,cateModels.get(position).getBrowseID(),productList,couponCode,
				onFlingStateChangedListener,currencyCode,currencyCodeStr);
	}
	
	@Override
	public void setPrimaryItem(ViewGroup container, int position, Object object) {
		//该方法可以获取到当前的Fragment对象
		currentFragment = (LandingPageCategoryFragment) object;
		super.setPrimaryItem(container, position, object);
	}
	
	/**
	 * 返回当前fragment对象
	 * @return
	 */
	public LandingPageCategoryFragment getCurrentFragment(){
		return currentFragment;
	}
	
}
